package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.Arranging;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 排号mapper
 * @author pang
 */
@Repository
public interface ArrangingMapper {

    /**
     * 新增排号信息
     * @param arranging
     * @return
     */
    @Insert("INSERT INTO arranging(typeId,takeTime,takeDate,state,phoneNum,dinersCount) " +
            "VALUES(#{typeId},#{takeTime},#{takeDate},#{state},#{phoneNum},#{dinersCount})")
    int insert(Arranging arranging);

    /**
     * 更新排号信息
     * @param arranging
     * @return
     */
    @Update("UPDATE arranging SET typeId=#{typeId},takeTime=#{takeTime},takeDate=#{takeDate},state=#{state},phoneNum=#{phoneNum},dinersCount=#{dinersCount} WHERE id=#{id}")
    int update(Arranging arranging);

    /**
     * 删除排号
     * @param id
     * @return
     */
    @Delete("DELETE FROM arranging WHERE id = #{id}")
    int delete(@Param("id") Integer id);


    /**
     * 查询排号
     * @param currPage
     * @param pageSize
     * @return
     */
    @Select("SELECT * FROM arranging LIMIT #{curr},#{size}")
    @Results(value = {
            @Result(column = "typeId",property = "tableType",one = @One(select = "com.xuetang9.t9.hotel.mapper.ITableTypeMapper.select",fetchType = FetchType.EAGER))
    })
    List<Arranging> selectByAll(@Param("curr") Integer currPage,@Param("size") Integer pageSize);


    /**
     * 获取当天的全部排号记录
     * @return
     */
    @Select("SELECT * FROM arranging WHERE TO_DAYS(takeDate) = TO_DAYS(NOW()) ORDER BY id ASC")
    List<Arranging> selectByTodayAll();

    /**
     * 获取当天的全部排号记录(根据餐桌类型)
     * @return
     */
    @Select("SELECT * FROM arranging WHERE TO_DAYS(takeDate) = TO_DAYS(NOW()) AND typeId = #{id} AND state = '等待' ORDER BY id ASC")
    List<Arranging> selectByTodayTableAll(@Param("id")Integer id);

    /**
     * 查询排号总数据条数
     * @return
     */
    @Select("SELECT COUNT(*) FROM arranging LIMIT #{curr},#{size}")
    Long selectByCount();
}
